how to react to object changes in javascript